package com.pym.service.impl;

import com.pym.dao.PymUploadPhotoDao;
import com.pym.dao.PymWpgjDao;
import com.pym.dao.PymWpxxDao;
import com.pym.entity.PymUploadPhoto;
import com.pym.entity.PymWpgj;
import com.pym.entity.PymWpxx;
import com.pym.service.PymWpdjService;
import com.pym.util.pymUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.stereotype.Service;
import java.util.*;

/**
 * @ClassName
 * @Description TODO
 * @Author wmj
 * @Date 2021/8/21
 * @Version 1.0
 **/

@Service
public class PymWpdjServiceImpl implements PymWpdjService {

    @Autowired
    private PymWpxxDao pymWpxxDao;

    @Autowired
    private PymUploadPhotoDao pymUploadPhotoDao;

    @Autowired
    private PymWpgjDao pymWpgjDao;

    @Override
    public int wpdjService(PymWpxx pymWpxx, String czrName, String czrIdCard, String domain, String path) {

        pymWpxx.setId(pymUtil.generateUUID());
        pymWpxx.setWpzt("1");
        pymWpxx.setWpbh(pymUtil.generateUUID());

        int i = pymWpxxDao.insert(pymWpxx);
        if(i > 0){
            PymWpgj pymWpgj = new PymWpgj();
            pymWpgj.setId(pymUtil.generateUUID());
            pymWpgj.setWpId(pymWpxx.getId());
            pymWpgj.setWpbh(pymWpxx.getWpbh());
            pymWpgj.setType("6");
            pymWpgj.setCzrIdCard(czrIdCard);
            pymWpgj.setCznr("登记成功！！");
            pymWpgj.setCzrName(czrName);
            pymWpgj.setOrgCode("440300000000");
            pymWpgj.setOrgName("深圳市公安局南山分局");
            pymWpgj.setIsDel("0");
            pymWpgjDao.insert(pymWpgj);

            PymUploadPhoto pymUploadPhoto = new PymUploadPhoto();
            pymUploadPhoto.setId(pymUtil.generateUUID());
            pymUploadPhoto.setBusinessId(pymWpxx.getId());
            pymUploadPhoto.setDomain(domain);
            pymUploadPhoto.setPath(path);
            pymUploadPhoto.setBusinessType("01");
            pymUploadPhoto.setIsDel("0");
            //设置照片开始截取的位置
            int start = path.lastIndexOf("/") + 1;
            pymUploadPhoto.setName(path.substring(start));
            pymUploadPhoto.setAddUser(pymWpxx.getAddUser());
            pymUploadPhoto.setFileSize("500");
            pymUploadPhotoDao.insert((pymUploadPhoto));
            return 1;
        }
        return 0;
    }

//    @Override
//    public int wpdjService(PymWpxx pymWpxx, PymWpgj pymWpgj, PymUploadPhoto pymUploadPhoto) {
//        pymWpxx.setWpzt("1");
//        int i = pymWpxxDao.insert(pymWpxx);
//        pymUploadPhotoDao.insert(pymUploadPhoto);
//        if(i != 0){
//            pymWpgj.setType("6");
//            pymWpgj.setCznr("登记成功");
//            pymWpgjDao.insert(pymWpgj);
//            return 1;
//        }
//       return 0;
//    }

//    @Override
//    public int wpdjService(PymWpxx pymWpxx, String czrName,String czrIdCard,String domain,String path) {
//        pymWpxx.setWpzt("1");
//        int i = pymWpxxDao.insert(pymWpxx);
//        return 0;
//    }

    //前端传实体类到后台，对象属性都为空
//    @Override
//    public int wpdjService(PymWpxx pymWpxx,String czrName,String czrIdCard,String domain,String path) {
//        String id = pymUtil.generateUUID();
//        pymWpxx.setId(id);
//        pymWpxx.setWpzt("1");
//        int i = pymWpxxDao.insert(pymWpxx);
//        if(i != 0){
//            PymWpgj pymWpgj = new PymWpgj();
//            pymWpgj.setId(pymUtil.generateUUID());
//            pymWpgj.setWpId(pymWpxx.getId());
//            pymWpgj.setType("6");
//            pymWpgj.setCzrIdCard(czrIdCard);
//            pymWpgj.setCznr("登记成功！！");
//            pymWpgj.setCzrName(czrName);
//            pymWpgjDao.insert(pymWpgj);
//            PymUploadPhoto pymUploadPhoto = new PymUploadPhoto();
//            pymUploadPhoto.setId(pymUtil.generateUUID());
//            pymUploadPhoto.setBusinessId(id);
//            pymUploadPhoto.setDomain(domain);
//            pymUploadPhoto.setPath(path);
//            pymUploadPhotoDao.insert((pymUploadPhoto));
//            return 1;
//        }
//        return 0;
//    }
}
